<template>
  <forms ref="forms" :config="config" @submit:forms="onsubmit" :btns="btns">
  </forms>
</template>

<script>
export default {
  props: ['__iframe'],
  data(){
    let id = this.$get('id'), btns = undefined;
    let link_table = this.$get('link_table'),
        link_id = this.$get('link_id'),
        status = this.$get('status'),
        status_label = this.$get('status_label');

    let forms_config = {
      link_table: {label:'关联数据表',name:'link_table',type:'hidden',value:link_table,is_info:true,},
      link_id: {label:'关联数据ID',name:'link_id',type:'hidden',value:link_id,is_info:true,},
      status: {label:'状态',name:'status',type:'select_one',config:"",value:"",tips:"选择列表可以在 [系统配置->案件进度的状态列表] 进行配置"},
      status_label: {label:'状态别名',name:'status_label',type:'hidden',value:"",is_info:true},
      info: {label:'记录内容',name:'info',type:'text_more',tips:''},
      files: {label:'附件',name:'files',type:'file_imgs',tips:'',value:''},
    }
    if (id){
      forms_config.create_time = {label:'创建时间',name:'create_time',tips:''};
    }
    if (this.$get('is_info')){
      s94Mjs.each(forms_config, function (row){ row.is_info = true; });
      btns = [];
    }
    return {
      id: id,
      btns: btns,
      config: forms_config,
    }
  },
  methods: {
    onsubmit(formData){
      let url = this.id ? `/admin/model_project_log/edit?id=`+this.id : '/admin/model_project_log/add';
      ajax({url:url, method:'POST', data:formData}, (res)=>{
        if (this.__iframe){
          iframe.exe('/order/edit', 'get_model_project_log');
          iframe.hide('edit');
          if (!this.id) this.$refs['forms'].init();
        }else {
          this.$router.push('index');
        }
      }, (res)=>{
        if (res.errors) this.$refs['forms'].errors = res.errors;
      })

    }
  },
  watch: {
    'config.status.value'(v){
      this.config.status_label.value = v;
    }
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;
    if (this.id) {
      ajax({url:'/admin/model_project_log/info?id='+this.id, cache:true}, (res)=>{
        this.$refs['forms'].init(res.data);
        return false;
      }, ()=>{
        if (this.__iframe){
          iframe.remove('edit');
        }else {
          this.$router.push('index');
        }
      })
    }

    //其他初始化操作
    ajax({url:"/admin/model_project_log/config_map", cache:true}, (res)=>{
      this.config.status.config = res.data.status_map;
    })
  }
}
</script>
